﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BanVeXemPhim_Presentation
{
    public partial class UserControlPhimHot : UserControl
    {
        public UserControlPhimHot()
        {
            InitializeComponent();

            memoryBitmap=new Bitmap(this.Width,this.Height);
            memoryGraphic = Graphics.FromImage(memoryBitmap);
            timer1.Enabled = true;
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

        private Bitmap memoryBitmap;
        private Graphics memoryGraphic;
        private int _iBitmap=0;
        private int _nBitmap=0;
        private Bitmap[] _listHinhAnh;

        public Bitmap[] ListHinhAnh
        {
            get { return _listHinhAnh; }
            set
            {
                _listHinhAnh = value;
                if(_listHinhAnh!=null)
                    _nBitmap = _listHinhAnh.Length;
            }
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //base.OnPaintBackground(e);
        }

        private void UserControlPhimHot_Paint(object sender, PaintEventArgs e)
        {
            if(_listHinhAnh!=null)
            {
                if (_nBitmap > 0)
                {
                    memoryGraphic.DrawImage(_listHinhAnh[_iBitmap], 0, 0, this.Width, this.Height);
                    memoryGraphic.DrawImage(Properties.Resources.KhungHinh, 0, 0, this.Width, this.Height);
                    e.Graphics.DrawImage(memoryBitmap, 0, 0);
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(_nBitmap>0)
            {
                _iBitmap = (_iBitmap + 1) % _nBitmap;
                Invalidate();
                Refresh();
            }

        }
    }
}
